document.onkeydown = function (event) {
    var target, code, tag;
    if (!event) {
        event = window.event; //针对ie浏览器
        target = event.srcElement;
        code = event.keyCode;
        if (code == 13) {
            tag = target.tagName;
            if (tag == "TEXTAREA") {
                return true;
            } else {
                return false;
            }
        }
    } else {
        target = event.target; //针对遵循w3c标准的浏览器，如Firefox
        code = event.keyCode;
        if (code == 13) {
            tag = target.tagName;
            if (tag == "INPUT") {
                return false;
            } else {
                return true;
            }
        }
    }
};

//------- Start 判断输入的是否是证书和小数还有0

function CupperCase(obj) {//用户只能输入正负数与小数

    var resultValue = document.getElementById("A1PH_Level08");
    var pindex = resultValue.selectedIndex;
    var resulttxt = resultValue.options[pindex].text;
    var inum;
    var newValue;
    if (resulttxt == "0.01") {
        inum = 1;
    } else {
        inum = 2;
    }

    if (inum == 1) {

        if (isNaN(obj.value) && !/^-$/.test(obj.value)) {
            obj.value = "";
        }
        if (!/^[+-]?\d*\.{0,1}\d{0,1}$/.test(obj.value)) {
            obj.value = obj.value.replace(/\.\d{1,}$/, obj.value.substr(obj.value.indexOf('.'), inum));
            obj.value = newValue.replace('.', '');
        }
    } else {

        if (isNaN(obj.value) && !/^-$/.test(obj.value)) {
            obj.value = "";
        }
        if (!/^[+-]?\d*\.{0,1}\d{0,1}$/.test(obj.value)) {
            obj.value = obj.value.replace(/\.\d{1,}$/, obj.value.substr(obj.value.indexOf('.'), inum));
        }
    }
}


function Wonkeyup(obj) {//用户只能输入正负数与小数
    var inum = document.getElementById("A1PH_Level08").value;

    if (inum.length == 5) {
        inum = 4;
    } else {
        inum = 3;
    }

    if (isNaN(obj.value) && !/^-$/.test(obj.value)) {
        obj.value = "";
    }
    if (!/^[+-]?\d*\.{0,1}\d{0,1}$/.test(obj.value)) {
        obj.value = obj.value.replace(/\.\d{1,}$/, obj.value.substr(obj.value.indexOf('.'), inum));
    }
}

//------- End 判断输入的是否是证书和小数还有0


function Button2_onclick() {
    var mymessage = confirm("你确定需要保存吗？或者在检查一遍？");

    if (mymessage == true) {
        return true;


    } else {
        return false;
    }

}


function searchChange() {
    var resultValue = document.getElementById("A1PH_Level08");
    var pindex = resultValue.selectedIndex;
    var resulttxt = resultValue.options[pindex].text;

    if (resulttxt == "0.01") {
        document.getElementById("E24").value = 3;
        document.getElementById("E25").value = 3;
        document.getElementById("K1").value = 0.01;
        document.getElementById("K2").value = 1;

    } else if (resulttxt == "0.001") {
        document.getElementById("E24").value = 1;
        document.getElementById("E25").value = 1;
        document.getElementById("K1").value = 0.007;
        document.getElementById("K2").value = 0.4;
    }

}

function ResoultFloat(arg1, arg2) {
    var t1 = 0, t2 = 0, r1, r2;
    try {
        t1 = arg1.toString().split(".")[1].length
    } catch (e) {
    }
    try {
        t2 = arg2.toString().split(".")[1].length
    } catch (e) {
    }
    with (Math) {
        r1 = Number(arg1.toString().replace(".", ""));
        r2 = Number(arg2.toString().replace(".", ""));
        return (r1 / r2) * pow(10, t2 - t1);
    }

}


function _SetDigitalInput(oInput) {
    var inum = document.getElementById("A1PH_Level08").value;

    if (inum.length == 5) {
        inum = 3;
    } else {
        inum = 2;
    }

    if (oInput == 1 || oInput == 7 || oInput == 13 || oInput == 19 || oInput == 25 || oInput == 31 || oInput == 37 || oInput == 43 || oInput == 49 || oInput == 55 || oInput == 61 || oInput == 67 || oInput == 73 || oInput == 79 || oInput == 85) {

        f = oInput - 2 + 1;

        j = oInput + 1;

        i = oInput + 1 + 1;

        k = oInput + 2 + 1;

        m = oInput + 3 + 1;

    } else {

        f = oInput - 2;
        j = oInput - 1;
        i = oInput + 1;
        k = oInput + 2;
        m = oInput + 3
    }

    //var f=oInput-2;
    //var j=oInput-1;
    //var i=oInput+1;
    //var k=oInput+2;
    //var m=oInput+3;
    var fValue01 = document.getElementById("B" + j).value == "" ? 0 : Number(document.getElementById("B" + j).value);
    var fValue02 = document.getElementById("B" + oInput).value == "" ? 0 : Number(document.getElementById("B" + oInput).value);

    var f_d = fValue01 + fValue02;


    var f_x = ResoultFloat(f_d * 10000, 2) / 10000;


    var f_y = changeTwoDecimal_y(f_x, inum) - parseFloat(document.getElementById("B" + f).value);
    document.getElementById("B" + i).value = changeTwoDecimal_y(f_x, inum);
    document.getElementById("B" + k).value = changeTwoDecimal_y(f_y, inum);

    var imxs = Math.max(document.getElementById("B4").value, document.getElementById("B10").value,
        document.getElementById("B16").value, document.getElementById("B22").value,
        document.getElementById("B28").value, document.getElementById("B34").value,
        document.getElementById("B40").value, document.getElementById("B46").value,
        document.getElementById("B52").value, document.getElementById("B58").value,
        document.getElementById("B64").value, document.getElementById("B70").value,
        document.getElementById("B76").value, document.getElementById("B82").value,
        document.getElementById("B88").value);


    var imins = Math.max(document.getElementById("B4").value, document.getElementById("B10").value,
        document.getElementById("B16").value, document.getElementById("B22").value,
        document.getElementById("B28").value, document.getElementById("B34").value,
        document.getElementById("B40").value, document.getElementById("B46").value,
        document.getElementById("B52").value, document.getElementById("B58").value,
        document.getElementById("B64").value, document.getElementById("B70").value,
        document.getElementById("B76").value, document.getElementById("B82").value,
        document.getElementById("B88").value);

    if (Math.abs(imxs) >= Math.abs(imins)) {

        document.getElementById("B5").value = document.getElementById("B11").value =
            document.getElementById("B17").value = document.getElementById("B23").value =
                document.getElementById("B29").value = document.getElementById("B35").value =
                    document.getElementById("B41").value = document.getElementById("B47").value =
                        document.getElementById("B53").value = document.getElementById("B59").value =
                            document.getElementById("B65").value = document.getElementById("B71").value =
                                document.getElementById("B77").value = document.getElementById("B83").value =
                                    document.getElementById("B89").value = imxs;


    } else {
        document.getElementById("B5").value = document.getElementById("B11").value =
            document.getElementById("B17").value = document.getElementById("B23").value =
                document.getElementById("B29").value = document.getElementById("B35").value =
                    document.getElementById("B41").value = document.getElementById("B47").value =
                        document.getElementById("B53").value = document.getElementById("B59").value =
                            document.getElementById("B65").value = document.getElementById("B71").value =
                                document.getElementById("B77").value = document.getElementById("B83").value =
                                    document.getElementById("B89").value = imins;


    }

}


function SetDigitalInput(oInput) {
    var inum = document.getElementById("A1PH_Level08").value;
    var isnum = 2;

    if (inum.length == 5) {
        inum = 1;
        isnum = 3;
    } else {
        inum = 0;
        isnum = 2;
    }

    if (document.getElementById("A1PH_Dy10").value != "" && document.getElementById("C49").value == "") {
        const dy10Value = parseFloat(document.getElementById("A1PH_Dy10").value);
        document.getElementById("C49").value = !isNaN(dy10Value) ? dy10Value.toFixed(1) : '';
        document.getElementById("C98").value =  !isNaN(dy10Value) ? (-Math.abs(dy10Value)).toFixed(1) : '';
        document.getElementById("C106").value = !isNaN(dy10Value) ? dy10Value.toFixed(1) : '';
    } else if (document.getElementById("A1PH_Dy10").value == "" && document.getElementById("C49").value == "") {
        document.getElementById("C49").value = 1500;
        document.getElementById("C98").value = -1500;
        document.getElementById("C106").value = 1500;
    }

    if (oInput == 1 || oInput == 8 || oInput == 15 || oInput == 22 | oInput == 29 || oInput == 36 || oInput == 43 || oInput == 50 || oInput == 57 || oInput == 64 || oInput == 71 || oInput == 78 || oInput == 85 || oInput == 92 || oInput == 99) {

        f = oInput - 2 + 1;
        j = oInput + 1;
        i = oInput + 1 + 1;
        k = oInput + 1 + 1 + 1;
        m = oInput + 3 + 1;

    } else {

        f = oInput - 2;
        j = oInput - 1;
        i = oInput + 1;
        k = oInput + 2;
        m = oInput + 3;

    }
    //  var f=oInput-2;
    //  var j=oInput-1;
    //  var i=oInput+1;
    //  var k=oInput+2;
    //var m = oInput + 3;

    var fValue01 = document.getElementById("C" + j).value == "" ? 0 : parseFloat(document.getElementById("C" + j).value);

    var fValue02 = document.getElementById("C" + oInput).value == "" ? 0 : parseFloat(document.getElementById("C" + oInput).value);


    var f_d = fValue01 + fValue02;
    var f_s = ResoultFloat(f_d * 10000, 2) / 10000;

    var f_x = changeTwoDecimal_y(f_s, inum);
    var f_y = changeTwoDecimal_y(f_x - document.getElementById("C" + f).value, inum);
    var f_m = f_y / parseFloat(document.getElementById("C106").value) * 100;

    document.getElementById("C" + i).value = f_x;
    document.getElementById("C" + k).value = f_y;

    document.getElementById("C" + m).value = changeTwoDecimal_y(f_m, isnum);

    if (oInput != 105) {
        var imxs = Math.max(document.getElementById("C5").value, document.getElementById("C12").value,
            document.getElementById("C19").value, document.getElementById("C26").value,
            document.getElementById("C33").value, document.getElementById("C40").value,
            document.getElementById("C47").value, document.getElementById("C54").value,
            document.getElementById("C61").value, document.getElementById("C68").value,
            document.getElementById("C75").value, document.getElementById("C82").value,
            document.getElementById("C89").value, document.getElementById("C96").value,
            document.getElementById("C103").value);

        var imins = Math.min(document.getElementById("C5").value, document.getElementById("C12").value,
            document.getElementById("C19").value, document.getElementById("C26").value,
            document.getElementById("C33").value, document.getElementById("C40").value,
            document.getElementById("C47").value, document.getElementById("C54").value,
            document.getElementById("C61").value, document.getElementById("C68").value,
            document.getElementById("C75").value, document.getElementById("C82").value,
            document.getElementById("C89").value, document.getElementById("C96").value,
            document.getElementById("C103").value);

        if (Math.abs(imxs) >= Math.abs(imins)) {
            document.getElementById("C6").value = document.getElementById("C13").value =
                document.getElementById("C20").value = document.getElementById("C27").value =
                    document.getElementById("C34").value = document.getElementById("C41").value =
                        document.getElementById("C48").value = document.getElementById("C55").value =
                            document.getElementById("C62").value = document.getElementById("C69").value =
                                document.getElementById("C76").value = document.getElementById("C83").value =
                                    document.getElementById("C90").value = document.getElementById("C97").value =
                                        document.getElementById("C104").value = changeTwoDecimal_y(imxs, isnum);

        } else {

            document.getElementById("C6").value = document.getElementById("C13").value =
                document.getElementById("C20").value = document.getElementById("C27").value =
                    document.getElementById("C34").value = document.getElementById("C41").value =
                        document.getElementById("C48").value = document.getElementById("C55").value =
                            document.getElementById("C62").value = document.getElementById("C69").value =
                                document.getElementById("C76").value = document.getElementById("C83").value =
                                    document.getElementById("C90").value = document.getElementById("C97").value =
                                        document.getElementById("C104").value = changeTwoDecimal_y(imins, isnum);

        }

    }


}

function SetDigitalInputD(oInput) {
    var inum = document.getElementById("A1PH_Level08").value;

    if (inum.length == 5) {
        inum = 3;
    } else {
        inum = 2;
    }


    if (oInput == 2 || oInput == 9) {
        f = oInput + 2;
        j = oInput + 1;
        i = oInput + 3;
    } else if (oInput == 3 || oInput == 10) {
        f = oInput - 1;
        j = oInput + 1;
        i = oInput + 2;

    } else {

        f = oInput - 2;
        j = oInput - 1;
        i = oInput + 1;
    }


    var fValue02 = document.getElementById("D" + j).value == "" ? 0 : parseFloat(document.getElementById("D" + j).value);

    var fValue01 = document.getElementById("D" + f).value == "" ? 0 : parseFloat(document.getElementById("D" + f).value);

    var fValue03 = document.getElementById("D" + oInput).value == "" ? 0 : parseFloat(document.getElementById("D" + oInput).value);


    var f_d = fValue01 + fValue02 + fValue03;
    var f_x = ResoultFloat(f_d * 10000, 3) / 10000;

    document.getElementById("D" + i).value = changeTwoDecimal_y(f_x, inum);


    if (document.getElementById("D12").value.toString() != "") {
        var iValue = Math.abs(parseFloat(document.getElementById("D5").value - document.getElementById("D12").value) * 0.059157 / 1000000000);

        // 修改：将数值乘以10的12次方
        iValue = iValue * Math.pow(10, 12);

        // 根据inum值保留相应小数位数
        if (inum == 3) {
            document.getElementById("D6").value = iValue.toFixed(3);
            document.getElementById("D13").value = iValue.toFixed(3);
        } else {
            document.getElementById("D6").value = iValue.toFixed(2);
            document.getElementById("D13").value = iValue.toFixed(2);
        }
    }
}

function SetDigitalInputE(oInput) {
    var inum = document.getElementById("A1PH_Level08").value;

    if (inum.length == 5) {
        inum = 3;
    } else {
        inum = 2;
    }
    var inums = inum;

    if (oInput == 0 || oInput == 6 || oInput == 12 || oInput == 18) {
        f = oInput + 1;

        j = oInput + 2;

        i = oInput + 3;


    } else if (oInput == 1 || oInput == 7 || oInput == 13 || oInput == 19) {
        f = oInput - 1;
        j = oInput + 1;
        i = oInput + 2;
    } else {

        f = oInput - 2;
        j = oInput - 1;
        i = oInput + 1;
    }
    //var f=oInput-2;
    //var j=oInput-1;
    //var i=oInput+1;

    var fValue02 = document.getElementById("E" + j).value == "" ? 0 : parseFloat(document.getElementById("E" + j).value);

    var fValue01 = document.getElementById("E" + f).value == "" ? 0 : parseFloat(document.getElementById("E" + f).value);

    var fValue03 = document.getElementById("E" + oInput).value == "" ? 0 : parseFloat(document.getElementById("E" + oInput).value);


    var f_d = fValue01 + fValue02 + fValue03;
    var f_x = ResoultFloat(f_d * 10000, 3) / 10000;

    document.getElementById("E" + i).value = changeTwoDecimal_y(f_x, inum);

    if (oInput == 8 || oInput == 2 || oInput == 1 || oInput == 7 || oInput == 0 || oInput == 6) {
        document.getElementById("E4").value = document.getElementById("E10").value = changeTwoDecimal_y(Math.abs((document.getElementById("E3").value == "" ? 0 : document.getElementById("E3").value) - parseFloat(document.getElementById("E9").value == "" ? 0 : document.getElementById("E9").value)) / 2, inum);
    }
    if (oInput == 20 || oInput == 14 || oInput == 13 || oInput == 19 || oInput == 12 || oInput == 18) {
        document.getElementById("E16").value = document.getElementById("E22").value = changeTwoDecimal_y(Math.abs((document.getElementById("E15").value == "" ? 0 : document.getElementById("E15").value) - parseFloat(document.getElementById("E21").value == "" ? 0 : document.getElementById("E21").value)) / 2, inum);
    }
    var f_l = "";
    var imax = changeTwoDecimal_y(Math.max(document.getElementById("E4").value, document.getElementById("E10").value, document.getElementById("E16").value, document.getElementById("E22").value), inum);
    if (parseFloat(imax) == 0) {
        if (document.getElementById("A1PH_Level08").value.length == 5) {
            f_l = 0.001 / 2;

        } else {
            f_l = 0.01 / 2;
        }


    } else {
        f_l = imax;
    }

    var f_k = parseInt(document.getElementById("E24").value == "" ? 0 : document.getElementById("E24").value);


    var f_f = (3 * 1000000000 * f_k) / f_l;

    // 修改：将数值乘以10的12次方
    f_f = f_f * Math.pow(10, -12);

    // 根据inum值保留相应小数位数
    if (inum == 3) {
        document.getElementById("E5").value = f_f.toFixed(3);
        document.getElementById("E11").value = f_f.toFixed(3);
        document.getElementById("E17").value = f_f.toFixed(3);
        document.getElementById("E23").value = f_f.toFixed(3);
    } else {
        document.getElementById("E5").value = f_f.toFixed(2);
        document.getElementById("E11").value = f_f.toFixed(2);
        document.getElementById("E17").value = f_f.toFixed(2);
        document.getElementById("E23").value = f_f.toFixed(2);
    }

    // 设置E_max字段的值
    var e4Value = document.getElementById("E4").value;
    var e16Value = document.getElementById("E16").value;
    var e_maxElement = document.getElementById("E_max");
    
    // 如果E_max元素存在，则设置其值
    if (e_maxElement) {
        if (e4Value !== "" && e16Value !== "") {
            // 两个值都存在时，选择较大的值
            e_maxElement.value = Math.max(parseFloat(e4Value), parseFloat(e16Value));
        } else if (e4Value !== "") {
            // 只有E4存在
            e_maxElement.value = e4Value;
        } else if (e16Value !== "") {
            // 只有E16存在
            e_maxElement.value = e16Value;
        }
    }

}

function SetDigitalInputF(oInput) {
    var inum = document.getElementById("A1PH_Level08").value;
    if (inum == 0) {
        alert("请选择仪器级别，确定输入小数位(0.01/0.001)");
        return false;
    } else {
        if (inum.length == 5) {
            inum = 3;
        } else {
            inum = 2;
        }
    }

    if (oInput == 3 || oInput == 11 || oInput == 19 || oInput == 27 || oInput == 35) {
        t = oInput - 3;
        n = oInput - 2;
        f = oInput - 1;
        j = oInput + 1;
        i = oInput + 2;
        k = oInput + 3;
        m = oInput + 4;

    } else {
        t = oInput - 4;
        n = oInput - 3;
        f = oInput - 2;
        j = oInput - 1;
        i = oInput + 1;
        k = oInput + 2;
        m = oInput + 3;

    }
    //var t=oInput-4;
    //var n=oInput-3;
    //var f=oInput-2;
    //var j=oInput-1;
    //var i=oInput+1;
    //var k=oInput+2;
    //var m=oInput+3;

    var fValue02 = parseFloat(document.getElementById("F" + j).value == "" ? 0 : document.getElementById("F" + j).value);

    var fValue01 = parseFloat(document.getElementById("F" + oInput).value == "" ? 0 : document.getElementById("F" + oInput).value);

    var fValue03 = parseFloat(document.getElementById("F" + f).value == "" ? 0 : document.getElementById("F" + f).value);

    var f_d = fValue01 + fValue02;
    var f_x = ResoultFloat(f_d * 10000, 2) / 10000;


    //var f_s = (document.getElementById("F" + n).value == "" ? 0 : document.getElementById("F" + n).value);


    document.getElementById("F" + i).value = changeTwoDecimal_y(f_x, inum);


    if (document.getElementById("F" + n).value == "") {
        document.getElementById("F" + m).value = "/";

    } else {
        var f_s = parseFloat(document.getElementById("F" + n).value) - parseFloat(document.getElementById("F" + t).value);
        document.getElementById("F" + m).value = changeTwoDecimal_y(f_s, inum);

    }


    document.getElementById("F" + k).value = changeTwoDecimal_y((f_x - fValue03) / 2, inum);
    
    // 新增功能：计算F_szwc的值
    updateValue([6, 14, 22, 30, 38], "F", "F_szwc");
    updateValue([7, 15, 23, 31, 39], "F", "F_cwwc");

}

// 新增函数：计算绝对值最大的正值
function updateValue(fieldIndexes, fieldPrefix, targetFieldId) {
    var values = [];
    
    // 收集所有非空字段的值
    for (var idx = 0; idx < fieldIndexes.length; idx++) {
        var fieldId = fieldPrefix + fieldIndexes[idx];
        var fieldElement = document.getElementById(fieldId);
        
        if (fieldElement && fieldElement.value !== "" && fieldElement.value !== "/") {
            values.push(parseFloat(fieldElement.value));
        }
    }
    
    // 如果有值，计算绝对值最大的值
    if (values.length > 0) {
        var maxAbsValue = values[0];
        var maxAbs = Math.abs(values[0]);
        
        for (var i = 1; i < values.length; i++) {
            var absValue = Math.abs(values[i]);
            // 如果找到更大的绝对值，或者绝对值相等但当前是正值，则更新
            if (absValue > maxAbs || (absValue === maxAbs && values[i] > 0 && maxAbsValue < 0)) {
                maxAbsValue = values[i];
                maxAbs = absValue;
            }
        }
        
        // 设置目标字段的值
        var targetElement = document.getElementById(targetFieldId);
        if (targetElement) {
            var inum = document.getElementById("A1PH_Level08").value;
            var decimalPlaces = (inum.length == 5) ? 3 : 2;
            targetElement.value = changeTwoDecimal_y(maxAbsValue, decimalPlaces);
        }
    }
}

function SetDigitalInputH(oInput) {

    var inum = document.getElementById("A1PH_Level08").value;

    if (inum.length == 5) {
        inum = 3;
    } else {
        inum = 2;
    }


    var H_1 = parseFloat(document.getElementById("H2").value == "" ? 0 : document.getElementById("H2").value);
    var H_2 = parseFloat(document.getElementById("H7").value == "" ? 0 : document.getElementById("H7").value);
    var H_3 = parseFloat(document.getElementById("H12").value == "" ? 0 : document.getElementById("H12").value);
    var H_4 = parseFloat(document.getElementById("H17").value == "" ? 0 : document.getElementById("H17").value);
    var H_5 = parseFloat(document.getElementById("H22").value == "" ? 0 : document.getElementById("H22").value);
    var H_6 = parseFloat(document.getElementById("H27").value == "" ? 0 : document.getElementById("H27").value);


    var f_d = H_1 + H_2 + H_3 + H_4 + H_5 + H_6;
    var Avg_x = ResoultFloat(f_d, 6);

    document.getElementById("H3").value = document.getElementById("H8").value
        = document.getElementById("H13").value = document.getElementById("H18").value
        = document.getElementById("H23").value = document.getElementById("H28").value = changeTwoDecimal_y(Avg_x, inum);


    var J_1 = (H_1 - Avg_x) * (H_1 - Avg_x);
    var J_2 = (H_2 - Avg_x) * (H_2 - Avg_x);
    var J_3 = (H_3 - Avg_x) * (H_3 - Avg_x);
    var J_4 = (H_4 - Avg_x) * (H_4 - Avg_x);
    var J_5 = (H_5 - Avg_x) * (H_5 - Avg_x);
    var J_6 = (H_6 - Avg_x) * (H_6 - Avg_x);

    var s_7 = (J_1 + J_2 + J_3 + J_4 + J_5 + J_6) / 5;

    var f_f = Math.pow(parseFloat(s_7), 0.5);


    document.getElementById("H4").value = document.getElementById("H9").value
        = document.getElementById("H14").value = document.getElementById("H19").value
        = document.getElementById("H24").value = document.getElementById("H29").value = changeTwoDecimal_y(f_f, inum);

    //if(isNaN(document.getElementById("H2").value) || isNaN(document.getElementById("H7").value)
    //|| isNaN(document.getElementById("H12").value) || isNaN(document.getElementById("H17").value)
    //|| isNaN(document.getElementById("H22").value) || isNaN(document.getElementById("H27").value))
    //{

    //  document.getElementById("H3").value=document.getElementById("H8").value
    //  =document.getElementById("H13").value=document.getElementById("H18").value
    //  =document.getElementById("H23").value=document.getElementById("H28").value
    //  =document.getElementById("H4").value=document.getElementById("H9").value
    //  =document.getElementById("H14").value=document.getElementById("H19").value
    //  =document.getElementById("H24").value=document.getElementById("H29").value=document.getElementById("H27").value="/";
    //}
    //else
    //{

    //  //var Avg_x = (H_1+H_2+H_3+H_4+H_5+H_6)/6;


    //}

    if (inum == 3) {
        document.getElementById("K3").value = 0.007;
    } else if (inum == 2) {
        document.getElementById("K3").value = 0.01;
    }

    // 计算H_szwc的值，即H3-H26
    var h3Value = parseFloat(document.getElementById("H3").value) || 0;
    var h26Value = parseFloat(document.getElementById("H26").value) || 0;
    var h_szwc = h3Value - h26Value;
    // 假设页面中存在H_szwc元素，设置其值
    var h_szwcElement = document.getElementById("H_szwc");
    if (h_szwcElement) {
        h_szwcElement.value = changeTwoDecimal_y(h_szwc, inum);
    }

}

function SetDigitalInputG(oInput) {

    var inum = document.getElementById("A1PH_Level08").value;

    if (inum.length == 5) {
        inum = 3;
    } else {
        inum = 2;
    }

    var f_1 = parseFloat(document.getElementById("G1").value == "" ? 0 : document.getElementById("G1").value);
    var f_2 = parseFloat(document.getElementById("G2").value == "" ? 0 : document.getElementById("G2").value);
    var f_3 = parseFloat(document.getElementById("G3").value == "" ? 0 : document.getElementById("G3").value);
    var f_4 = parseFloat(document.getElementById("G4").value == "" ? 0 : document.getElementById("G4").value);
    var f_5 = parseFloat(document.getElementById("G5").value == "" ? 0 : document.getElementById("G5").value);
    var f_6 = parseFloat(document.getElementById("G6").value == "" ? 0 : document.getElementById("G6").value);

    // var Avg_x =(f_1+f_2+f_3+f_4+f_5+f_6)/6;

    var f_d = f_1 + f_2 + f_3 + f_4 + f_5 + f_6;

    var Avg_x = changeTwoDecimal_y(ResoultFloat(f_d * 10000, 6) / 10000, inum);


    var J_1 = (f_1 - Avg_x) * (f_1 - Avg_x);
    var J_2 = (f_2 - Avg_x) * (f_2 - Avg_x);
    var J_3 = (f_3 - Avg_x) * (f_3 - Avg_x);
    var J_4 = (f_4 - Avg_x) * (f_4 - Avg_x);
    var J_5 = (f_5 - Avg_x) * (f_5 - Avg_x);
    var J_6 = (f_6 - Avg_x) * (f_6 - Avg_x);

    var s_7 = (J_1 + J_2 + J_3 + J_4 + J_5 + J_6) / 5;


    var f_f = Math.pow(parseFloat(s_7), 0.5);


    document.getElementById("G7").value = changeTwoDecimal_y(f_f, inum);


}

function changeTwoDecimal_f(x) {
    var f_x = parseFloat(x);
    if (isNaN(f_x)) {
        alert('function:changeTwoDecimal->parameter error');
        return false;
    }
    f_x = Math.round(f_x * 10000) / 10000;
    var s_x = f_x.toString();
    var pos_decimal = s_x.indexOf('.');
    if (pos_decimal < 0) {
        pos_decimal = s_x.length;
        s_x += '.';
    }
    while (s_x.length <= pos_decimal + 3) {
        s_x += '0';
    }
    return s_x;
}

function changeTwoDecimal_y(s_x, inum) {
    s_x = s_x.toFixed(inum + 1);
    if (isNaN(s_x)) {
        alert('function:changeTwoDecimal->parameter error');
        return false;
    }

    s_x = s_x.toString();


    var pdecimal = s_x.indexOf('.');

    if (pdecimal < 0) {
        pdecimal = s_x.length;
        s_x += '.';
    }

    while (s_x.length < parseInt(parseInt(pdecimal) + parseInt(inum + 3))) {
        s_x += '0';
    }


    var inums = inum + s_x.indexOf('.');


    var iReturnValue = "";

    if (s_x.length > (parseInt(inums) + 3)) {
        s_x = s_x.substring(0, (parseInt(inums) + 3));
    }


    if (s_x.length == (parseInt(inums) + 3)) {


        var s_x_l = parseInt(s_x.substring(s_x.length - 1, s_x.length));
        var s_x_S = parseInt(s_x.substring(s_x.length - 2, s_x.length - 1));
        var s_x_T = parseInt(s_x.substring(s_x.length - 3, s_x.length - 2));


        if (s_x_S != 5) {
            return iReturnValue = parseFloat(s_x).toFixed(inum);

        } else if (s_x_S == 5 && s_x_l != 0) {
            return iReturnValue = parseFloat(s_x).toFixed(inum);

        } else if (s_x_S == 5 && s_x_l == 0) {
            if (s_x_T % 2 == 0) {
                return iReturnValue = parseFloat(s_x.substring(0, parseInt(inums + 1))).toFixed(inum);

            } else {

                if (inum == 1) {

                    var iValue = parseFloat(s_x.substring(0, parseInt(inums + 1)));

                    if (parseFloat(s_x) >= 0) {

                        return iReturnValue = parseFloat(iValue + 0.1).toFixed(inum);
                    } else {

                        return iReturnValue = parseFloat(iValue - 0.1).toFixed(inum);
                    }


                } else if (inum == 2 || inum == 3) {
                    if (parseFloat(s_x) >= 0) {
                        return iReturnValue = parseFloat(parseFloat(s_x.substring(0, parseInt(inums + 1))) + parseFloat(inum == 2 ? 0.01 : 0.001)).toFixed(inum);
                    } else {

                        return iReturnValue = parseFloat(parseFloat(s_x.substring(0, parseInt(inums + 1))) + parseFloat(inum == 2 ? (-0.01) : (-0.001))).toFixed(inum);
                    }

                } else {

                    return iReturnValue = parseFloat(s_x.substring(0, parseInt(inums + 1))).toFixed(inum);


                }
            }

        }

    }


}

function Setnum(oInput) {
    const f_x = parseFloat(document.getElementById("A1PH_Dy10").value);
    document.getElementById("C49").value = !isNaN(f_x) ? f_x.toFixed(1) : '';
    document.getElementById("C98").value = !isNaN(f_x) ? (-Math.abs(f_x)).toFixed(1) : '';
    document.getElementById("C106").value = !isNaN(f_x) ? f_x.toFixed(1) : '';

}



